﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_RawMaterialReceiveController : BaseApiController
    {
        #region DI

        public PB_RawMaterialReceiveController(IPB_RawMaterialReceiveBusiness pB_RawMaterialReceiveBus)
        {
            _pB_RawMaterialReceiveBus = pB_RawMaterialReceiveBus;
        }

        IPB_RawMaterialReceiveBusiness _pB_RawMaterialReceiveBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_RawMaterialReceive>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_RawMaterialReceiveBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_RawMaterialReceive> GetTheData(IdInputDTO input)
        {
            return await _pB_RawMaterialReceiveBus.GetTheDataAsync(input.id);
        }
        /// <summary>
        /// 材料耗用流水
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_RawMaterialReceiveDTO>> GetDataDTOList(PageInput<PB_RawMaterialReceiveConditionDTO> input)
        {
            return await _pB_RawMaterialReceiveBus.GetDataDTOListAsync(input);
        }
        /// <summary>
        /// 材料耗用统计
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_RawMaterialReceiveDTO>> GetDataTotalDTOList(PageInput<PB_RawMaterialReceiveConditionDTO> input)
        {
            return await _pB_RawMaterialReceiveBus.GetDataTotalDTOListAsync(input);
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_RawMaterialReceive data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_RawMaterialReceiveBus.AddDataAsync(data);
            }
            else
            {
                await _pB_RawMaterialReceiveBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_RawMaterialReceiveBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}